package com.gosling.gosling.mobao;

import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import com.alipay.api.domain.Product;
import com.gosling.cloudspace.common.entity.pojo.OrderInfoPO;
import com.gosling.cloudspace.config.ThreadPool;
import com.gosling.cloudspace.tools.CollectionTool;
import com.gosling.cloudspace.tools.FileTool;
import com.gosling.cloudspace.tools.IOTool;
import com.gosling.cloudspace.tools.SnowflakeIdTool;
import org.apache.commons.codec.binary.Base64InputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.IOUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.multipart.MultipartFile;
import org.xml.sax.SAXException;
import org.xml.sax.ext.Attributes2Impl;

import javax.xml.stream.*;
import javax.xml.stream.events.*;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @Software: IntelliJ IDEA
 * @Addresses: www.gosling.com
 * @Email 1793327033@qq.com
 * @Classname lhltest
 * @Author: lihonglin
 * @Date: 2021/8/8 17:36
 */
@SuppressWarnings("all")
@SpringBootTest(classes = MobaoBusinessTest2.class)
@SpringBootApplication
public class MobaoBusinessTest2 {

    private static void setSaxElement(XMLStreamWriter xsw, String localName, String content) throws XMLStreamException {
        xsw.writeStartElement(localName);
        xsw.writeCharacters(content);
        xsw.writeEndElement();
    }

    private static void setSaxElement(XMLStreamWriter xsw, String localName) throws XMLStreamException {
        xsw.writeStartElement(localName);
        xsw.writeEndElement();
    }

    public static void main(String[] args) throws Exception {
        lbmd();
    }


    private static void lbmd() {
        long start = System.currentTimeMillis();
        ThreadPool threadPool = new ThreadPool();
        ThreadPoolTaskExecutor executor = threadPool.taskExecutor();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            list.add("" + i);
        }
        CountDownLatch countDownLatch = new CountDownLatch(list.size());
        for (String string : list) {
            try {
                executor.execute(() -> {
                    System.out.println(string);
                });
            } finally {
                countDownLatch.countDown();
                System.out.println("countdown:" + countDownLatch.getCount());
            }
        }
//        executor.shutdown();
        try {
            System.out.println("线程任务阻塞------->>>>>>>>>");
            countDownLatch.await();
        } catch (InterruptedException e) {
            System.out.println("中断异常抓取:{}");
            e.printStackTrace();
        }
        int activeCount = executor.getActiveCount();
        //等待线程执行完毕
        for (; ; ) {
            System.out.println("活跃线程还剩：" + executor.getActiveCount());
            if (executor.getActiveCount() == 0) {
                break;
            }
            System.out.println("等待线程执行完毕!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        executor.shutdown();
        long end = System.currentTimeMillis();
        System.out.println((end - start) / 1000 + "秒");
    }

    private static void sdf() {
        final AtomicInteger counter = new AtomicInteger();
        int workCount = 10;
        int andIncrement = counter.incrementAndGet();
        int andIncrement2 = counter.incrementAndGet();
        int andIncrement3 = counter.incrementAndGet();
        int andIncrement4 = counter.incrementAndGet();
        System.out.println(andIncrement);
        System.out.println(andIncrement2);
        System.out.println(andIncrement3);
        System.out.println(andIncrement4);
    }

    private static void lik() {
        按行读取();
    }

    public static void peek() {
//        cartSkuList
//                .stream()
//                .peek(sku -> System.out.println(sku.getSkuName()))
//                .forEach(item -> System.out.println(JSON.toJSONString(item, true)));
    }

    private static void kjh() {
        //       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MCC
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MCC BUSINESS_RELATION
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_CENTER_NOTICE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_CENTRE_ACCOUNT
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_CONFIG
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_ELECTRONIC_DATA
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_FEE_RATE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_FEE_RATE_SLAVE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_FUND_PAY
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_FUND_PAY_CARD
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_FUND_SETTLEMENT
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_INFO_NEW
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_INFO_OLD
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_IP_WHITELIST
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_ONLINE_PROTOCOL
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_PROTOCOL_FILE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_RELATION
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_SETTLEMENT_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_MERCHANT_SUBMITTED_NUC
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_NUCC_BUSINESS_KIND
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_PERSONAL FEE_RATE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_PLATFORM_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_PUSH_AGENT_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_SALESMAN
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_SERVICE_MERCHANT_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_STANDING_SIGN
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_UNION_AREA_CODE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_UNION_BANK_AREA_CODE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_UNION_BANK_NUMBER
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.BAS_WECHAT_BUSINESS_KIND
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.FREE_FORMAT
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.LOGMINER_20210810      2795912
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.LOGMINER_20210811      1322465
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.LOGMINER_20210923      8604354
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.LOGMINER_202109232     6022819
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.LOGMINER_20210928      589183
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.LOGMINER_202109282     624700
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_BATCH_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_BATCH_ORIGIN_DATA
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_BATCH_PAY_ACCOUNT
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_BATCH_PAY_TYPE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_BATCH_UNIONPAY_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_FILE_INFO
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_SERVICE_TYPE
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.MERCHANT_UNIONPAY_REPORT
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.PRODUCT_OPERATION_SEND
//       SELECT COUNT(0) FROM MOBAOPAY_AUDIT.RECIPT_CHAPTER
//
//MOBAOPAY_AUDIT.LOGMINER_20210810      条数：2795912
//MOBAOPAY_AUDIT.LOGMINER_20210811      条数：1322465
//MOBAOPAY_AUDIT.LOGMINER_20210923      条数：8604354
//MOBAOPAY_AUDIT.LOGMINER_202109232     条数：6022819
//MOBAOPAY_AUDIT.LOGMINER_20210928      条数：589183
//MOBAOPAY_AUDIT.LOGMINER_202109282     条数：624700


//        INFO  | 2022-08-23 09:45:36,373 |  mobao | [http-nio-7012-exec-6-100] (c.m.s.i.BankCardValidateServiceImpl:313) | 请求数盒魔方验证参数: {realName=唐韬, sceneCode=01, sign=c6e28c3fed3a5852ff2a10002bf95be1, appkey=jNA6QAdH, bankcard=6216653100004138198, custName=摩宝支付-问问阿萨啊-713, idNo=51082119991205843X, timestamp=1661219136358}
//        INFO  | 2022-08-23 09:45:36,375 |  mobao | [http-nio-7012-exec-6-100] (c.m.u.HttpUtils:83) | 请求地址：[https://api.soohaid.com:8211/api/bankcard/factor3Score]
//        INFO  | 2022-08-23 09:45:38,004 |  mobao | [http-nio-7012-exec-6-100] (c.m.u.HttpUtils:134) | 应答报文：{"result":{"score":"95.26"},"msg":"请求成功","code":"0","fee":1}
//        INFO  | 2022-08-23 09:45:38,006 |  mobao | [http-nio-7012-exec-6-100] (c.m.s.i.SoohaidServiceImpl:65) | 数盒魔方验证结果: {"result":{"score":"95.26"},"msg":"请求成功","code":"0","fee":1}
//        INFO  | 2022-08-23 09:45:38,007 |  mobao | [http-nio-7012-exec-6-100] (c.m.u.SoohaidSecretUtils:86) | msg:请求成功
//        INFO  | 2022-08-23 09:45:38,008 |  mobao | [http-nio-7012-exec-6-100] (c.m.u.SoohaidSecretUtils:89) | fee[是否收费]:1,收费
//        INFO  | 2022-08-23 09:45:38,010 |  mobao | [http-nio-7012-exec-6-100] (c.m.u.SoohaidSecretUtils:93) | 要素校验分数:95.26
//        INFO  | 2022-08-23 09:45:38,011 |  mobao | [http-nio-7012-exec-6-100] (c.m.u.SoohaidSecretUtils:100) | A:9,B:5,C:2,D:6
//        INFO  | 2022-08-23 09:45:38,012 |  mobao | [http-nio-7012-exec-6-100] (c.m.s.i.BankCardValidateServiceImpl:319) | 数盒魔方三要素校验成功: {"result":{"score":"95.26"},"msg":"请求成功","code":"0","fee":1}
    }

    private static void eqw() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(1);
        ArrayList<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        CountDownLatch countDownLatch = new CountDownLatch(list.size());
        for (String s : list) {
            executor.execute(() -> {
                System.out.println(s);
            });
            countDownLatch.countDown();
        }

        System.out.println();
    }

    private static void 按行读取() {
        File file = new File("D:\\aa.txt");
        BufferedReader reader = null;
        String temp = null;
        long line = 1;
        try {
            reader = new BufferedReader(new FileReader(file));
            while ((temp = reader.readLine()) != null) {
                System.out.println("line" + line + ":" + temp);
                if (line == 50) {
                    System.out.println("输出文件");
                }
                line++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IoUtil.close(reader);
        }
    }

    private static void cvd() {
        System.out.println(1 ^ 2);

        SnowflakeIdTool idWorker = new SnowflakeIdTool(1, 1);
        String orderId = idWorker.nextIdToString();
        String orderId1 = idWorker.nextIdToString();
        String orderId2 = idWorker.nextIdToString();

        System.out.println(orderId);
        System.out.println(orderId1);
        System.out.println(orderId2);

//        System.out.println(System.currentTimeMillis());
//        System.out.println(System.currentTimeMillis());
//        System.out.println(System.currentTimeMillis());

//        1009035 235951775744
//        1009035 235951775745
//        1009035 235951775746

//        1009035 306411888640
//        1009035 306411888641
//        1009035 306411888642

//        1009035 413131759616
//        1009035 413131759617
//        1009035 413131759618

//        1009036 115639930880
//        1009036 115639930881
//        1009036 115639930882
    }

    private static void lio() {
        //已经报备的
        Set<String> bussTpSetOld = new HashSet<>();
        bussTpSetOld.add("11");
        bussTpSetOld.add("16");

        //新录入的
        Set<String> bussTpSet = new HashSet<>();
        bussTpSet.add("11");
        bussTpSet.add("16");
        bussTpSet.add("15");
//        bussTpSet.add("10");

        System.out.println("现在的产品" + bussTpSet.toString());
        System.out.println("以前的产品" + bussTpSetOld.toString());
        Set<String> bussTpIntersection = CollectionTool.intersectionSet(bussTpSetOld, bussTpSet);
        Set<String> bussTpIntersection2 = CollectionTool.intersectionSet(bussTpSet, bussTpSetOld);
        System.out.println("以前和现在产品的交集[更新]" + bussTpIntersection.toString());
        System.out.println("以前和现在产品的交集[更新]" + bussTpIntersection2.toString());
        bussTpSet.addAll(bussTpSetOld);
        Set<String> set = CollectionTool.differenceSet(bussTpSet, bussTpSetOld);
        System.out.println("以前和现在产品的差集[新增]" + set.toString());
    }

    private static OrderInfoPO xcv(OrderInfoPO s) {
        OrderInfoPO orderInfoPO2 = new OrderInfoPO();
        orderInfoPO2.setOrderNo("SUCCESS");
        s = orderInfoPO2;
        return s;
    }

    private static void xxxsaada() {
        //操作标识,商户代码,商户服务类型,业务类型,产品功能套餐,商户经营名称,收单机构代码,商户类型,商户状态,是否开通免密免签,商户经营地址,商户法定名称,商户注册地址,国家地区代码,受理地区代码,商户英文名称,营业证明文件类型,营业证明文件号码,法人代表证件类型,法人代表证件号码,法人代表姓名,商户联系人,商户联系人电话,商户联系人邮箱,商户拓展方式,收单外包服务机构代码,商户计费算法,商户账号,商户账户名称,商户开户行行号,商户开户行名称,是否申请非标准价格,商户现场注册标识码,特殊计费类型,特殊计费档次,借记卡发卡银联分润算法,贷记卡发卡银联分润算法,非标交易类型及渠道,商户网址,网站或APP名称,ICP许可证编号,业务种类,备注
//     青海省-西宁市-湟中区-湟中县多巴镇多巴南街                  青海省-西宁市-湟中区
//     青海省-西宁市-城东区-车站商业办公安置区2号地B4楼                  青海省-西宁市-城东区
//     青海省-西宁市-城东区-商品批发市场三期一楼D-22号                  青海省-西宁市-城东区
//     青海省-海西蒙古族藏族自治州-格尔木市-青海省格尔木市盐桥南路27号                  青海省-海西蒙古族藏族自治州-格尔木市
//     青海省-西宁市-城东区-西宁市城东区八一西路33-1号                  青海省-西宁市-城东区
//     青海省-西宁市-湟中区-湟中县多巴镇多巴西街                  青海省-西宁市-湟中区
//     青海省-西宁市-城西区-海省西宁市城西区五四大街11号                  青海省-西宁市-城西区
//     青海省-海东市-乐都区-海东市乐都区碾伯镇李家村                  青海省-海东市-乐都区
//     青海省-西宁市-城东区-区共和南路2号1号楼2-16室                  青海省-西宁市-城东区
//     青海省-西宁市-城西区-街49号（永和大厦B座12楼）                  青海省-西宁市-城西区
//     青海省-西宁市-城东区-一路49-51号5号楼7号商铺                  青海省-西宁市-城东区
//     青海省-海南藏族自治州-贵南县-贵南县过马营镇友谊路                  青海省-海南藏族自治州-贵南县
//     青海省-西宁市-大通回族土族自治县-海生物科技产业园区经二路46号                  青海省-西宁市-大通回族土族自治县
//     青海省-海东市-循化撒拉族自治县-循化县积石镇西沟村                  青海省-海东市-循化撒拉族自治县
//     青海省-西宁市-城中区-2-001、002、027号）                  青海省-西宁市-城中区
//     青海省-西宁市-城东区-西宁市城东区八一东路33号                  青海省-西宁市-城东区
//     青海省-海北藏族自治州-刚察县-东川工业园区沪宁路8号6楼南侧                  青海省-海北藏族自治州-刚察县
//     青海省-西宁市-城中区-山路29号3号楼2单元231室                  青海省-西宁市-城中区
//     青海省-西宁市-城西区-市城西区胜利路59号1056室                  青海省-西宁市-城西区
//     青海省-海南藏族自治州-共和县-切吉乡哇玉市场                  青海省-海南藏族自治州-共和县
    }

    /**
     * 判断对象是否完全为空
     *
     * @param object
     * @return
     */
    public static boolean isNullAll(Object object) {
        //定义返回结果，默认为true
        boolean flag = true;
        if (Objects.isNull(object)) {
            flag = true;
        } else {
            // 得到类对象
            Class clazz = object.getClass();
            // 得到所有属性
            Field fields[] = clazz.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                Object fieldValue = null;
                try {
                    //得到属性值
                    fieldValue = field.get(object);
                    //得到属性类型
                    Type fieldType = field.getGenericType();
                    // 得到属性名
                    String fieldName = field.getName();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                //只要有一个属性值不为null 就返回false 表示对象不为null
                if (fieldValue != null) {
                    flag = false;
                    break;
                }
            }
        }
        return flag;
    }

    private static void adb() {
        //        String addr = "qq)606楼六园业产济经环循(号66道大业创道街溪东县远宁市州永省南";
        String addr3 = "湖南省永州市宁远县东溪街道创业大道66号(循环经济产业园六楼606)";
        String addr2 = "南省永州市宁远县东溪街道创业大道六十六号(循环经济产业园六楼六零六)";
        String addr = "壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、圆、角、分、零、整（正）";

//        System.out.println(truncateBackward2(addr, 60));
//        System.out.println(truncateBackward2(addr, 30));
        System.out.println(truncateBackward2(addr3, 30));

        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        Integer routeP = 0;
        for (int i = 0; i < list.size(); i++) {
            //优先级
            int routePri = list.get(i);
            routeP = routePri > routeP ? routeP : routePri;
        }
        System.out.println(routeP);
    }

    private static void hashmapTest() throws
            NoSuchFieldException, NoSuchMethodException, InterruptedException, IllegalAccessException, InvocationTargetException {
        //手动指定
        Map<String, String> m = new HashMap<>(8, 0.5f);
        //hashmap默认
        //Map<String, String> m = new HashMap<>();
        Class<?> mapType = m.getClass();
        Field threshold = mapType.getDeclaredField("threshold");
        threshold.setAccessible(true);
        Method capacity = mapType.getDeclaredMethod("capacity");
        capacity.setAccessible(true);
        Thread.sleep(300);
        System.out.println("容量：" + capacity.invoke(m) + " 阈值：" + threshold.get(m) + " 元素数量：" + m.size());
        for (int i = 0; i < 17; i++) {
            m.put("" + i, "" + i);
            System.out.println("容量：" + capacity.invoke(m) + " 阈值：" + threshold.get(m) + " 元素数量：" + m.size());
        }

        //默认
//        容量：16 阈值：0 元素数量：0
//        容量：16 阈值：12 元素数量：1
//        容量：16 阈值：12 元素数量：2
//        容量：16 阈值：12 元素数量：3
//        容量：16 阈值：12 元素数量：4
//        容量：16 阈值：12 元素数量：5
//        容量：16 阈值：12 元素数量：6
//        容量：16 阈值：12 元素数量：7
//        容量：16 阈值：12 元素数量：8
//        容量：16 阈值：12 元素数量：9
//        容量：16 阈值：12 元素数量：10
//        容量：16 阈值：12 元素数量：11
//        容量：16 阈值：12 元素数量：12
//        容量：32 阈值：24 元素数量：13
//        容量：32 阈值：24 元素数量：14
//        容量：32 阈值：24 元素数量：15
//        容量：32 阈值：24 元素数量：16
//        容量：32 阈值：24 元素数量：17

        //手动指定
//        容量：8 阈值：8 元素数量：0
//        容量：8 阈值：6 元素数量：1
//        容量：8 阈值：6 元素数量：2
//        容量：8 阈值：6 元素数量：3
//        容量：8 阈值：6 元素数量：4
//        容量：8 阈值：6 元素数量：5
//        容量：8 阈值：6 元素数量：6
//        容量：16 阈值：12 元素数量：7
//        容量：16 阈值：12 元素数量：8
//        容量：16 阈值：12 元素数量：9
//        容量：16 阈值：12 元素数量：10
//        容量：16 阈值：12 元素数量：11
//        容量：16 阈值：12 元素数量：12
//        容量：32 阈值：24 元素数量：13
//        容量：32 阈值：24 元素数量：14
//        容量：32 阈值：24 元素数量：15
//        容量：32 阈值：24 元素数量：16
//        容量：32 阈值：24 元素数量：17
    }

    private static void QWE() {
        SnowflakeIdTool idWorker = new SnowflakeIdTool(5, 8);
        String orderId = idWorker.nextIdToString();
        String orderId1 = idWorker.nextIdToString();
        String orderId2 = idWorker.nextIdToString();

        System.out.println(orderId);
        System.out.println(orderId1);
        System.out.println(orderId2);

        ArrayList<Product> productList = new ArrayList<>();
        String payType = "," + productList.stream().map(Product::getName).collect(Collectors.joining(",")) + ",";

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.MILLISECOND, 0);
        long l = (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000 / 60;
        System.out.println(l);
    }

    public static String truncateBackward2(String str, int len) {
        if (StringUtils.isBlank(str)) {
            return "";
        }
        char[] chrArr = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        int count = 0;
        //SRARA LEN = 8
        for (int i = chrArr.length - 1; i >= 0; i--) {
            char cc = chrArr[i];
            if (count < len) {
                if (isChinese(cc)) {
                    if (count + 1 == len) {
                        return sb.reverse().toString();
                    }
                    count = count + 2;
                    sb = sb.append(cc);
                } else {
                    count = count + 1;
                    sb = sb.append(cc);
                }
            } else {
                break;
            }
        }
        return sb.reverse().toString();
    }

    private static void xxx() {
        //AB.CD
        String score = "98.18";
        BigDecimal i = new BigDecimal(score);
        long x = i.multiply(new BigDecimal(100)).longValue();
        System.out.println(x);
        long X = x >>> 10;
        long X1 = x << 10;
        long X2 = x >> 1000;
        long D = x % 10;
        long C = x / 10 % 10;
        long B = x / 10 / 10 % 10;
        long A = x / 10 / 10 / 10 % 10;
        System.out.println("W" + X);
        System.out.println("W" + X1);
        System.out.println("W" + X2);
        System.out.println("个位数" + D);
        System.out.println("十位数" + C);
        System.out.println("百位数" + B);
        System.out.println("千位数" + A);
        if ((A + B + C) % 10 == D) {
            System.out.println("三要素校验成功");
        } else {
            System.out.println("三要素校验失败");
        }
//        String[] scoreSplit = score.split("[.]");
//        String before = scoreSplit[0];
//        String after = scoreSplit[1];
//        char[] charsBefore = before.toCharArray();
//        char[] charsAfter = after.toCharArray();
//        char[] a = {charsBefore[0]};
//        char[] b = {charsBefore[1]};
//        char[] c = {charsAfter[0]};
//        char[] d = {charsAfter[1]};
//        int A = Integer.parseInt(new String(a));
//        int B = Integer.parseInt(new String(b));
//        int C = Integer.parseInt(new String(c));
//        int D = Integer.parseInt(new String(d));
//        if ((A+B+C) % 10 == D){
//            System.out.println("三要素校验成功");
//        }
    }

    private static void urldecoder() throws UnsupportedEncodingException {
        String s = "/C:/Users/code_Genius/Desktop/%e6%96%87%e4%bb%b6%e5%90%88%e9%9b%86/JavaProject/personal-blog-project/target/classes/static/imgs/headerImgs";
        String b = "%e6%96%87%e4%bb%b6%e5%90%88%e9%9b%86";
        System.out.println(URLDecoder.decode(s, "UTF-8"));

        BigDecimal aa = new BigDecimal("100");
        BigDecimal bb = new BigDecimal("1000");
        System.out.println(aa.compareTo(bb));
    }

    private static void ssss() {
        List<String> columnList = new ArrayList<>();
        columnList.add("123");
        columnList.add("123");
        columnList.add("999");
        columnList.add("999");
        Set<String> objects = new HashSet<>(columnList);
        for (String object : objects) {
            System.out.println("去重：" + object);
        }

        List<String> collect = columnList.stream().filter(s -> !"123".equals(s)).collect(Collectors.toList());
        for (String s : collect) {
            System.out.println("过滤：" + s);
        }

        StringBuilder bussTpDic = new StringBuilder();

        int count = 0;
        for (String type : columnList) {
            //替换成对应的中文
            bussTpDic.append("22+");
            if (count != columnList.size() - 1) {
                bussTpDic.append(",");
            }
            count++;
        }
        System.out.println(bussTpDic.toString());

        path();
    }

    private static void path() {
        String path = MobaoBusinessTest2.class.getResource("/static/imgs/headerImgs").getPath();
        File file = new File(path);
        if (file.isDirectory()) {
            for (File listFile : file.listFiles()) {
                System.out.println(listFile.getName());
            }
        }
        System.out.println(path);
    }

    public static String truncateBackward1(String str, int len) {
        if (StringUtils.isBlank(str)) {
            return "";
        }
        char[] chrArr = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        int count = 0;
        //SRARA LEN = 8
        for (int i = chrArr.length - 1; i >= 0; i--) {
            char cc = chrArr[i];
            if (count < len) {
                if (isChinese(cc)) {
                    if (count + 1 == len) {
                        return sb.toString();
                    }
                    count = count + 2;
                    sb = sb.append(cc);
                } else {
                    count = count + 1;
                    sb = sb.append(cc);
                }
            } else {
                break;
            }
        }
        return sb.reverse().toString();
    }

    public static boolean isChinese(char c) {
//        String sb = String.valueOf(c);
//        return sb.getBytes().length > 1;

        String temp = String.valueOf(c);

        String chinese = "[\u0391-\uFFE5]";
        return temp.matches(chinese);
    }

    /***
     * 截取包含中文的字符串-从后往前截取
     *
     * @param str
     * @param len
     * @return
     */
    public static String truncateStrAfter(String str, int len) {
        if (StringUtils.isBlank(str)) {
            return "";
        }
        char[] chrArr = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        int count = 0;
        for (char cc : chrArr) {
            if (count < len) {
                if (isChinese(cc)) {
                    if (count + 1 == len) {
                        return sb.toString();
                    }
                    count = count + 2;
                    sb = sb.append(cc);
                } else {
                    count = count + 1;
                    sb = sb.append(cc);
                }
            } else {
                break;
            }
        }
        return sb.toString();
    }

    /***
     * 截取包含中文的字符串-从前往后截取
     *
     * @param str
     * @param len
     * @return
     */
    public static String truncateBackward(String str, int len) {
        if (StringUtils.isBlank(str)) {
            return "";
        }
        char[] chrArr = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        int count = 0;
        //SRARA LEN = 8
        for (int i = chrArr.length - 1; i >= 0; i--) {
            char cc = chrArr[i];
            if (count < len) {
                if (isChinese(cc)) {
                    if (count + 1 == len) {
                        return sb.toString();
                    }
                    count = count + 2;
                    sb = sb.append(cc);
                } else {
                    count = count + 1;
                    sb = sb.append(cc);
                }
            } else {
                break;
            }
        }
        return sb.reverse().toString();
    }

    public static int getChOrEnLength(String value) {
        int valueLength = 0;
        String chinese = "[\u0391-\uFFE5]";
        /* 获取字段值的长度，如果含中文字符，则每个中文字符长度为2，否则为1 */
        for (int i = 0; i < value.length(); i++) {
            /* 获取一个字符 */
            String temp = value.substring(i, i + 1);
            /* 判断是否为中文字符 */
            if (temp.matches(chinese)) {
                /* 中文字符长度为2 */
                valueLength += 2;
            } else {
                /* 其他字符长度为1 */
                valueLength += 1;
            }
        }
        return valueLength;
    }

    private static void format314() {
        String string = ",314,131,132,124,314,125,314,";
        String string2 = ",314,";
//        if (string2.length() == 5){
//            String replace = string2.replace("314", "");
//        }
//        String replace = string2.replace(",314", "");
//        System.out.println(replace);
        String[] split = string2.split(",");
        for (String s : split) {
            System.out.println("111:" + s);
        }
        System.out.println(split.length);
    }

    private static void MMM() {
        String s = "1290.990";
        boolean number = isMoney(s);
        System.out.println(number);
        BigDecimal money2 = isMoney2("1");
        System.out.println(money2.toString());
    }

    public static boolean isMoney(String str) {
        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,10})?$"); // 判断小数点后10位以内的数字的正则表达式
        Matcher match = pattern.matcher(str);
        return match.matches();
    }

    public static BigDecimal isMoney2(String str) {
        BigDecimal bigDecimal = BigDecimal.valueOf(0.0001);
        return bigDecimal;
    }

    private static void threadM() throws InterruptedException {
        //开始时间
        Date start = new Date();
        ThreadPool threadPool = new ThreadPool();
        ThreadPoolTaskExecutor executor = threadPool.taskExecutor();
        executor.execute(() -> {
            //主方法
            mainFunction(1);
        });
        //结束时间
        Date end;
        long between;
        int activeCount;
        do {
            //睡眠5分钟
            Thread.sleep(5 * 60 * 1000);
            end = new Date();
            activeCount = executor.getActiveCount();
            between = DateUtil.between(start, end, DateUnit.MINUTE);
            // 起始时间 + 30分钟 == end也可以跳出循环
        } while (activeCount > 0 && between < 30);

        if (between >= 30) {
            //发送短信
            sendMsg();
        }
    }

    public static String nDaysAgo(int nDays) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        calendar.add(Calendar.DATE, nDays);
        return sdf1.format(calendar.getTime());
    }

    public static String mainFunction(int nDays) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        calendar.add(Calendar.DATE, nDays);
        return sdf1.format(calendar.getTime());
    }

    public static String sendMsg() {
        return null;
    }

    private static void yiHuo() {
        boolean a = true;
        boolean b = false;
        //两个输入相同时为0，不同则为1
        boolean b1 = a ^ b;
        System.out.println(a);
        System.out.println(b);
        System.out.println(b1);
    }

    private static void doList() {
        int maxSize = 9;
        List<String> tradeCustomerNoList = new ArrayList<>();
        addList(tradeCustomerNoList);
        int totalCount = tradeCustomerNoList.size();
        int processCount = totalCount > maxSize ? totalCount / maxSize + 1 : 1;
        //更新最后一次交易时间一次性限制更新条数
        if (CollectionUtil.isNotEmpty(tradeCustomerNoList)) {
            int initSize = 1;
            do {
                int fromIndex = (initSize - 1) * maxSize;
                int toIndex = initSize * maxSize >= totalCount ? totalCount : initSize * maxSize;
                List<String> customerNos = tradeCustomerNoList.subList(fromIndex, toIndex);
                for (String customerNo : customerNos) {
                    System.out.println(customerNo);
                }
                initSize++;
            } while ((processCount -= 1) > 0);
        }
    }

    private static void addList(List<String> tradeCustomerNoList) {
        for (int i = 1; i < 21; i++) {
            tradeCustomerNoList.add("cust_no:" + i);
        }
    }

    private static void nDaysAgo() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        calendar.add(Calendar.DATE, -180);
        String nDaysAgo = sdf1.format(calendar.getTime());
        System.out.println(nDaysAgo);
    }

    private static void fileTypegetttttt() {
        try {
            String resource = "C:\\Users\\Administrator\\Desktop\\壁纸\\iTab2- - 副本.bmp";
            String name = "分支行信息.JPEG";
            FileInputStream input = new FileInputStream(new File(resource));
            MultipartFile multipartFile = new MockMultipartFile("file", name, "text/plain", input);
            InputStream inputStream = multipartFile.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            input.close();
            if (FileTool.isPngOrJpegOrJpg(multipartFile)) {
                System.out.println("成功");
            } else {
                System.out.println("失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }

    private static byte[] getFormat(InputStream input) {
        try (DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(input))) {
            //要读取几个字节具体看文件头的长度
            byte[] bytes = new byte[4];
            dataInputStream.read(bytes);
            return bytes;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static void decoder11() throws UnsupportedEncodingException {
        String s = "cHJpdmF0ZSBzdGF0aWMgdm9pZCBzZXRFbGVtZW50NShYTUxXcml0ZXIgeHN3LCBYTUxFdmVudFJlYWRlciByZWFkZXIpIHRocm93cyBYTUxTdHJlYW1FeGNlcHRpb24sDQogICAgICAgICAgIFNBWEV4Y2VwdGlvbiwgSU9FeGNlcHRpb24gew0KICAgICAgeHN3LnNldEVzY2FwZVRleHQoZmFsc2UpOw0KICAgICAgeHN3LnN0YXJ0RG9jdW1lbnQoKTsNCiAgICAgIHhzdy5zdGFydFByZWZpeE1hcHBpbmcoIiIsICJodHRwOi8vd3d3LnNhYWMuZ292LmNuL3N0YW5kYXJkcy9FUk0vZW5jYXBzdWxhdGlvbiIpOw0KICAgICAgeHN3LmVuZFByZWZpeE1hcHBpbmcoIiIpOw0KICAgICAgeHN3LnN0YXJ0UHJlZml4TWFwcGluZygieHNpIiwgImh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIik7DQogICAgICB4c3cuZW5kUHJlZml4TWFwcGluZygieHNpIik7DQogICAgICBBdHRyaWJ1dGVzMkltcGwgYXR0cmlidXRlczIgPSBuZXcgQXR0cmlidXRlczJJbXBsKCk7DQogICAgICBhdHRyaWJ1dGVzMi5hZGRBdHRyaWJ1dGUoImh0dHA6Ly93d3cuc2FhYy5nb3YuY24vc3RhbmRhcmRzL0VSTS9lbmNhcHN1bGF0aW9uIGVlcC54c2QiLA0KICAgICAgICAgICAgICAiIiwgInhzaTpzY2hlbWFMb2NhdGlvbiIsICIiLCAiaHR0cDovL3d3dy5zYWFjLmdvdi5jbi9zdGFuZGFyZHMvRVJNL2VuY2Fwc3VsYXRpb24gZWVwLnhzZCIpOw0KICAgICAgeHN3LnN0YXJ0RWxlbWVudCgiIiwgIueUteWtkOaWh+S7tuWwgeijheWMhSIsICLnlLXlrZDmlofku7blsIHoo4XljIUiLCBhdHRyaWJ1dGVzMik7DQogICAgICBTdHJpbmcgbmFtZVN0ciA9IG51bGw7DQogICAgICBTdHJpbmcgbmFtZSA9IG51bGw7DQogICAgICBBdHRyaWJ1dGVzMkltcGwgYXR0ciA9IG5ldyBBdHRyaWJ1dGVzMkltcGwoKTsNCiAgICAgIHdoaWxlIChyZWFkZXIuaGFzTmV4dCgpKSB7DQogICAgICAgICBBdHRyaWJ1dGVzMkltcGwgYXR0cjIgPSBuZXcgQXR0cmlidXRlczJJbXBsKCk7DQogICAgICAgICBYTUxFdmVudCBldmVudCA9IHJlYWRlci5uZXh0RXZlbnQoKTsNCiAgICAgICAgIFN0cmluZyBjaGFyYWN0ZXJzRGF0YSA9IG51bGw7DQogICAgICAgICBpZiAoZXZlbnQuaXNTdGFydEVsZW1lbnQoKSkgew0KICAgICAgICAgICAgU3RhcnRFbGVtZW50IHN0YXJ0RWxlbWVudCA9IGV2ZW50LmFzU3RhcnRFbGVtZW50KCk7DQogICAgICAgICAgICBpZiAoc3RhcnRFbGVtZW50LmdldE5hbWUoKS5nZXRMb2NhbFBhcnQoKS5lcXVhbHMoIueUteWtkOaWh+S7tuWwgeijheWMhSIpKSB7DQogICAgICAgICAgICAgICBjb250aW51ZTsNCiAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICBuYW1lID0gc3RhcnRFbGVtZW50LmdldE5hbWUoKS5nZXRMb2NhbFBhcnQoKTsNCiAgICAgICAgICAgICAgIGlmIChuYW1lLmVxdWFscygi5paH5qGj5pWw5o2uIikpew0KICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7DQogICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICBJdGVyYXRvciBhdHRyaWJ1dGVzID0gc3RhcnRFbGVtZW50LmdldEF0dHJpYnV0ZXMoKTsNCiAgICAgICAgICAgICAgIHdoaWxlIChhdHRyaWJ1dGVzLmhhc05leHQoKSkgew0KICAgICAgICAgICAgICAgICAgQXR0cmlidXRlIGF0dHJpYnV0ZSA9IChBdHRyaWJ1dGUpIGF0dHJpYnV0ZXMubmV4dCgpOw0KICAgICAgICAgICAgICAgICAgU3RyaW5nIGxvY2FsUGFydCA9IGF0dHJpYnV0ZS5nZXROYW1lKCkuZ2V0TG9jYWxQYXJ0KCk7DQogICAgICAgICAgICAgICAgICBTdHJpbmcgdmFsdWUgPSBhdHRyaWJ1dGUuZ2V0VmFsdWUoKTsNCiAgICAgICAgICAgICAgICAgIFN0cmluZyBkdGRUeXBlID0gYXR0cmlidXRlLmdldERURFR5cGUoKTsNCiAgICAgICAgICAgICAgICAgIGF0dHIyLmFkZEF0dHJpYnV0ZShudWxsLCBsb2NhbFBhcnQsIGxvY2FsUGFydCwgZHRkVHlwZSwgdmFsdWUpOw0KICAgICAgICAgICAgICAgfQ0KICAgICAgICAgICAgICAgaWYgKG5hbWVTdHIgPT0gbnVsbCkgew0KICAgICAgICAgICAgICAgICAgYXR0ciA9IGF0dHIyOw0KICAgICAgICAgICAgICAgICAgbmFtZVN0ciA9IG5hbWU7DQogICAgICAgICAgICAgICB9IGVsc2Ugew0KICAgICAgICAgICAgICAgICAgeHN3LnN0YXJ0RWxlbWVudCgiIiwgbmFtZVN0ciwgbmFtZVN0ciwgYXR0cik7DQogICAgICAgICAgICAgICAgICBuYW1lU3RyID0gbmFtZTsNCiAgICAgICAgICAgICAgICAgIGF0dHIgPSBhdHRyMjsNCiAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgIH0gZWxzZSBpZiAoZXZlbnQuaXNFbmRFbGVtZW50KCkpIHsNCiAgICAgICAgICAgIEVuZEVsZW1lbnQgZW5kRWxlbWVudCA9IGV2ZW50LmFzRW5kRWxlbWVudCgpOw0KICAgICAgICAgICAgbmFtZSA9IGVuZEVsZW1lbnQuZ2V0TmFtZSgpLmdldExvY2FsUGFydCgpOw0KICAgICAgICAgICAgaWYgKG5hbWVTdHIgIT0gbnVsbCkgew0KICAgICAgICAgICAgICAgeHN3LnN0YXJ0RWxlbWVudCgiIiwgbmFtZVN0ciwgbmFtZVN0ciwgYXR0cik7DQogICAgICAgICAgICAgICB4c3cuZW5kRWxlbWVudCgiIiwgbmFtZSwgbmFtZSk7DQogICAgICAgICAgICAgICBhdHRyLmNsZWFyKCk7DQogICAgICAgICAgICAgICBuYW1lU3RyID0gbnVsbDsNCiAgICAgICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICB4c3cuZW5kRWxlbWVudCgiIiwgbmFtZSwgbmFtZSk7DQogICAgICAgICAgICB9DQogICAgICAgICB9IGVsc2UgaWYgKGV2ZW50LmdldEV2ZW50VHlwZSgpID09IFhNTFN0cmVhbUNvbnN0YW50cy5DSEFSQUNURVJTKSB7DQogICAgICAgICAgICBpZiAoIWV2ZW50LmFzQ2hhcmFjdGVycygpLmlzV2hpdGVTcGFjZSgpKSB7DQogICAgICAgICAgICAgICBpZiAobmFtZVN0ciAhPSBudWxsKSB7DQogICAgICAgICAgICAgICAgICB4c3cuc3RhcnRFbGVtZW50KCIiLCBuYW1lU3RyLCBuYW1lU3RyLCBhdHRyKTsNCiAgICAgICAgICAgICAgICAgIHhzdy53cml0ZShuYW1lU3RyLmVxdWFscygi57yW56CB5pWw5o2uIikgPyAiIiA6IGV2ZW50LmFzQ2hhcmFjdGVycygpLmdldERhdGEoKSk7DQogICAgICAgICAgICAgICAgICBhdHRyLmNsZWFyKCk7DQogICAgICAgICAgICAgICAgICBuYW1lU3RyID0gbnVsbDsNCiAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0NCiAgICAgICAgIH0NCiAgICAgIH0NCiAgIH0=";
        byte[] decode = Base64.getDecoder().decode(s);
        String s1 = new String(decode, "UTF-8");
        System.out.println(s1);
    }

    public static void test13() {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.IS_COALESCING, true);
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        InputStream is = null;
        FileWriter out = null;
        XMLWriter xmlWriter = null;
        XMLEventReader reader = null;
        try {
            is = new FileInputStream("D:\\123456.xml");
            out = new FileWriter("D:\\12345678.xml");
            reader = factory.createXMLEventReader(is);
            xmlWriter = new XMLWriter(out, OutputFormat.createPrettyPrint());
            setElement(xmlWriter, reader);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
            IOTool.closeQuietly(reader);
            IOTool.closeQuietly(xmlWriter);
            IOTool.closeQuietly(out);
        }
    }

    private static byte[] getBytes(char[] chars) {
        CharBuffer put = CharBuffer.allocate(chars.length).put(chars);
        put.flip();
        return Charset.forName("UTF-8").encode(put).array();
    }

    public static void test16() {
        try {
            Base64Encoder decoder = new Base64Encoder();
            File originFile = new File("D:/base64Decoder/text.java");
            File encoderFile = new File("D:/base64Decoder/text2.txt");
            File decoderFile = new File("D:/base64Decoder/text3.java");
            InputStreamReader reader = new InputStreamReader(new Base64InputStream(new FileInputStream(originFile), true, -1, null));
            FileOutputStream outEncoder = new FileOutputStream(encoderFile);
            FileOutputStream outDecoder = new FileOutputStream(decoderFile);
            char[] chars = new char[4096];
            int n;
            while ((n = reader.read(chars)) >= 0) {
                byte[] bytes = getBytes(chars);
                outEncoder.write(bytes, 0, n);
            }
            outEncoder.close();
            reader.close();
            FileInputStream in = new FileInputStream(encoderFile);
            outDecoder.close();
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String file2String(File file) {
        try {
            BufferedReader buffer = new BufferedReader(new FileReader(file));
            StringBuilder sb = new StringBuilder();
            String temp;
            while ((temp = buffer.readLine()) != null) {
                sb.append(temp);
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void test14() {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.IS_COALESCING, true);
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        XMLWriter xmlWriter = null;
        XMLEventReader reader = null;
        try {
            reader = factory.createXMLEventReader(new FileInputStream("D:\\test.xml"));
            xmlWriter = new XMLWriter(new FileOutputStream("D:\\12345678.xml"), OutputFormat.createPrettyPrint());
            setElement5(xmlWriter, reader);
            xmlWriter.endDocument();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOTool.closeQuietly(xmlWriter);
            IOTool.closeQuietly(reader);
        }
    }

    public static void test15() {
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty(XMLInputFactory.IS_COALESCING, true);
        factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        InputStream is = null;
        FileWriter out = null;
        XMLStreamWriter xmlWriter = null;
        XMLEventReader reader = null;
        try {
            is = new FileInputStream("D:\\123456.xml");
            reader = factory.createXMLEventReader(is);
            xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream("D:\\12345678.xml"), "UTF-8");
            Document document = DocumentHelper.createDocument();
            Element rss = document.addElement("电子文件封装包", "http://www.saac.gov.cn/standards/ERM/encapsulation");
            setElement3(rss, reader);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
            IOTool.closeQuietly(reader);
            IOTool.closeQuietly(xmlWriter);
            IOTool.closeQuietly(out);
        }
    }

    private static void setElement(XMLWriter xmlWriter, XMLEventReader reader) throws
            XMLStreamException, SAXException, IOException {
        xmlWriter.setEscapeText(false);
        xmlWriter.startDocument();
        xmlWriter.startPrefixMapping("", "http://www.saac.gov.cn/standards/ERM/encapsulation");
        xmlWriter.endPrefixMapping("");
        xmlWriter.startPrefixMapping("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        xmlWriter.endPrefixMapping("xsi");
        Attributes2Impl attributes2 = new Attributes2Impl();
        attributes2.addAttribute("http://www.saac.gov.cn/standards/ERM/encapsulation eep.xsd",
                "", "xsi:schemaLocation", "", "http://www.saac.gov.cn/standards/ERM/encapsulation eep.xsd");
        xmlWriter.startElement("", "电子文件封装包", "电子文件封装包", attributes2);
        String name = null;
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            String charactersData = null;
            int eventType = event.getEventType();
            System.out.println();
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                name = startElement.getName().getLocalPart();
                if (name.equals("电子文件封装包")) {
                    continue;
                }
                Iterator attributes = startElement.getAttributes();
                Attributes2Impl attr = new Attributes2Impl();
                while (attributes.hasNext()) {
                    Attribute attribute = (Attribute) attributes.next();
                    String localPart = attribute.getName().getLocalPart();
                    String value = attribute.getValue();
                    String dtdType = attribute.getDTDType();
                    attr.addAttribute(null, localPart, localPart, dtdType, value);
                }
                if (name.equals("编码数据")) {
                    String refId = null;
                    for (int i = 0; i < attr.getLength(); i++) {
                        String refIdOrEncodeId = attr.getValue(i);
                        if (refIdOrEncodeId.equals("引用编码数据ID")) {
                            refId = refIdOrEncodeId;
                        }
                    }
                    if (refId == null) {
                        xmlWriter.startElement(null, name, name, attr);
                    } else {
                        xmlWriter.startElement(null, name, name, attr);
                        xmlWriter.write("");
                    }
                    xmlWriter.endElement(null, name, name);
                } else {
                    XMLEvent xmlEvent = reader.nextEvent();
                    if (xmlEvent.getEventType() == XMLStreamConstants.CHARACTERS) {
                        if (!xmlEvent.asCharacters().isWhiteSpace()) {
                            Characters characters = xmlEvent.asCharacters();
                            charactersData = characters.getData();
                        }
                    }
                    xmlWriter.startElement(null, name, name, attr);
                    xmlWriter.write(charactersData == null ? "" : charactersData);
                }
            } else if (event.isEndElement()) {
                EndElement endElement = event.asEndElement();
                name = endElement.getName().getLocalPart();
                xmlWriter.endElement(null, name, name);
            } else {
                if (name != null && !name.equals("编码数据") && !name.equals("电子文件封装包")) {
                    System.out.println(name);
                    xmlWriter.endElement(null, name, name);
                }
            }
        }
        xmlWriter.endElement("", "电子文件封装包", "电子文件封装包");
        xmlWriter.endDocument();
    }

    private static void setElement2(XMLStreamWriter xsw, XMLEventReader reader) throws XMLStreamException,
            SAXException, IOException {
        xsw.writeStartDocument("UTF-8", "1.0");
        xsw.writeStartElement("电子文件封装包");
        xsw.writeNamespace("", "http://www.saac.gov.cn/standards/ERM/encapsulation");
        xsw.writeNamespace("xsi", " http://www.w3.org/2001/XMLSchema-instance");
        xsw.writeAttribute("xsi:schemaLocation", "http://www.saac.gov.cn/standards/ERM/encapsulation eep.xsd");
        String name = null;
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            String charactersData = null;
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                name = startElement.getName().getLocalPart();
                if (name.equals("电子文件封装包")) {
                    continue;
                }
                Iterator attributes = startElement.getAttributes();
                Attributes2Impl attr = new Attributes2Impl();
                while (attributes.hasNext()) {
                    Attribute attribute = (Attribute) attributes.next();
                    String localPart = attribute.getName().getLocalPart();
                    String value = attribute.getValue();
                    String dtdType = attribute.getDTDType();
                    attr.addAttribute(null, localPart, localPart, dtdType, value);
                }
                XMLEvent xmlEvent = reader.nextEvent();
                if (xmlEvent.getEventType() == XMLStreamConstants.CHARACTERS) {
                    if (!xmlEvent.asCharacters().isWhiteSpace()) {
                        Characters characters = xmlEvent.asCharacters();
                        charactersData = characters.getData();
                    }
                }
                xsw.writeStartElement(name);
                xsw.writeCharacters(charactersData == null ? "" : charactersData);
            } else if (event.isEndElement()) {
                EndElement endElement = event.asEndElement();
                name = endElement.getName().getLocalPart();
            } else {
                if (name != null && !name.equals("编码数据") && !name.equals("电子文件封装包")) {
                    xsw.writeEndElement();
                }
            }
        }
    }

    private static void setElement3(Element chilElement, XMLEventReader reader) throws XMLStreamException,
            SAXException, IOException {
        String name = null;
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            String charactersData = null;
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                name = startElement.getName().getLocalPart();
                if (name.equals("电子文件封装包")) {
                    continue;
                }
                Iterator attributes = startElement.getAttributes();
                Attributes2Impl attr = new Attributes2Impl();
                while (attributes.hasNext()) {
                    Attribute attribute = (Attribute) attributes.next();
                    String localPart = attribute.getName().getLocalPart();
                    String value = attribute.getValue();
                    String dtdType = attribute.getDTDType();
                    attr.addAttribute(null, localPart, localPart, dtdType, value);
                }
                XMLEvent xmlEvent = reader.nextEvent();
                if (xmlEvent.getEventType() == XMLStreamConstants.CHARACTERS) {
                    if (!xmlEvent.asCharacters().isWhiteSpace()) {
                        Characters characters = xmlEvent.asCharacters();
                        charactersData = characters.getData();
                    }
                }
//            xsw.writeStartElement(name);
//            xsw.writeCharacters(charactersData == null ? "" : charactersData);
            } else if (event.isEndElement()) {
                EndElement endElement = event.asEndElement();
                name = endElement.getName().getLocalPart();
            } else {
                if (name != null && !name.equals("编码数据") && !name.equals("电子文件封装包")) {
//               xsw.writeEndElement();
                }
            }
        }
    }

    /***
     * XML递归读取并生成的通用方法-不会溢出
     * @param xsw
     * @param reader
     * @throws XMLStreamException
     * @throws SAXException
     * @throws IOException
     */
    private static void setElement5(XMLWriter xsw, XMLEventReader reader) throws XMLStreamException,
            SAXException, IOException {
        xsw.setEscapeText(false);
        xsw.startDocument();
        xsw.startPrefixMapping("", "http://www.saac.gov.cn/standards/ERM/encapsulation");
        xsw.endPrefixMapping("");
        xsw.startPrefixMapping("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        xsw.endPrefixMapping("xsi");
        Attributes2Impl attributes2 = new Attributes2Impl();
        attributes2.addAttribute("http://www.saac.gov.cn/standards/ERM/encapsulation eep.xsd",
                "", "xsi:schemaLocation", "", "http://www.saac.gov.cn/standards/ERM/encapsulation eep.xsd");
        xsw.startElement("", "电子文件封装包", "电子文件封装包", attributes2);
        String extension = null;
        String nameStr = null;
        String name = null;
        Attributes2Impl attr = new Attributes2Impl();
        while (reader.hasNext()) {
            Attributes2Impl attr2 = new Attributes2Impl();
            XMLEvent event = reader.nextEvent();
            String charactersData = null;
            if (event.isStartElement()) {
                StartElement startElement = event.asStartElement();
                if (startElement.getName().getLocalPart().equals("电子文件封装包")) {
                    continue;
                } else {
                    name = startElement.getName().getLocalPart();
                    if (name.equals("文档数据")) {
                        System.out.println();
                    }
                    Iterator attributes = startElement.getAttributes();
                    while (attributes.hasNext()) {
                        Attribute attribute = (Attribute) attributes.next();
                        String localPart = attribute.getName().getLocalPart();
                        String value = attribute.getValue();
                        String dtdType = attribute.getDTDType();
                        attr2.addAttribute(null, localPart, localPart, dtdType, value);
                    }
                    if (nameStr == null) {
                        attr = attr2;
                        nameStr = name;
                    } else {
                        xsw.startElement("", nameStr, nameStr, attr);
                        nameStr = name;
                        attr = attr2;
                    }
                }
            } else if (event.isEndElement()) {
                EndElement endElement = event.asEndElement();
                name = endElement.getName().getLocalPart();
                if (nameStr != null) {
                    xsw.startElement("", nameStr, nameStr, attr);
                    xsw.endElement("", name, name);
                    attr.clear();
                    nameStr = null;
                } else {
                    xsw.endElement("", name, name);
                }
            } else if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
                if (!event.asCharacters().isWhiteSpace()) {
                    if (nameStr != null) {
                        xsw.startElement("", nameStr, nameStr, attr);
                        if (nameStr.equals("编码数据")) {
                            BufferedOutputStream bufferedOutputStream = null;
                            //目标文件（base64解码生成）
                            String deCoderPathDir = "d:/base64Decoder/";
                            String fileName = UUID.randomUUID().toString() + "." + extension;
                            extension = null;
                            String deCoderPath = deCoderPathDir + fileName;
                            byte[] buffer = new byte[4096];
                            try {
                                File dir = new File(deCoderPathDir);
                                if (!dir.exists()) {
                                    dir.mkdirs();
                                }
                                File deCoderFile = new File(deCoderPath);
                                if (!deCoderFile.exists()) {
                                    deCoderFile.createNewFile();
                                }
                                bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(deCoderFile));
                                String data = event.asCharacters().getData();
//                        buffer = new BASE64Decoder().decodeBuffer(data);
                                bufferedOutputStream.write(buffer);
                            } catch (IOException e) {
                                e.printStackTrace();
                            } finally {
                                IOTool.closeQuietly(bufferedOutputStream);
                            }
                            xsw.write(deCoderPath);
                        } else {
                            if (nameStr.equals("计算机文件名")) {
                                String data = event.asCharacters().getData();
                                String[] split = data.split("[.]");
                                extension = split[split.length - 1];
                            }
                            xsw.write(event.asCharacters().getData());
                        }
                        attr.clear();
                        nameStr = null;
                    }
                }
            }
        }
    }

    public static String truncateStr(String str, int len) {
        if (str == null || str.equals("") || len == 0)
            return "";
        char[] chrArr = str.toCharArray();
        StringBuilder sb = new StringBuilder("");
        int count = 0;
        for (char cc : chrArr) {
            if (count < len) {
                if (isChinese(cc)) {
                    if (count + 1 == len)
                        return sb.toString();
                    count = count + 2;
                    sb = sb.append(cc);
                } else {
                    count = count + 1;
                    sb = sb.append(cc);
                }
            } else {
                break;
            }
        }
        return sb.toString();
    }

    public String getOrderOutNo1() {
        StringBuilder str = new StringBuilder();
//        //清算
//        str.append(CommonConstants.QS);
//        //出款
//        str.append(CommonConstants.TRADE_TYPE_3);
//        //今日日期
//        str.append(DateUtil.format(new Date(),"yyyyMMddHHmmss"));
//        String serialNo = getIncreasingNo(CommonConstants.QS+CommonConstants.TRADE_TYPE_3,6,'0');
//        str.append(serialNo);
//        System.out.println("生成内部出款订单号"+str);
        return str.toString();
    }

    public void s25() {
//自动结算订单查询,支付订单查询,退款订单查询,转账到银行卡查询,提现查询,转账订单查询,充值订单查询,资金代发订单查询,电子章使用记录查询;
//
//银行卡管理,转账到银行卡申请,转账到银行卡复核;
//
//商户盗料,修改登陆密码,修改支付密码;
//
//操作员管理,权限管理,操作日志;
//
//绑定个人管理,绑定商户管理,订单分账流水,失败待处理订单;
//
//账户明细查询,对账单查询,账户日终余额表;
//
//代发银行卡,资金代发发起,资金代发复核;
//
//支付账户转账,绑定商户管理,绑定个人管理;
    }

    public void sbcv1() {
//商户基本信息,商户结算信息,商户费率管理,商户指定路由配置,商户即时结算,商户密钥查询,商户正件到到期预警,自主入网商户审核,资金代发商户配置,商户访问IP白名单,商户绑定关系,商户充值费率管理,商户电子协议管理,移动二维码,跨境商户绑定关系,商户批量导入;
//
//代理商基本信息;
//
//销售基本信息,分公司基本信息,部门基本信息,平台号管理;
//
//个人基本信息,个人绑卡信息,个人实名认证记录,个人支付账户返现设置,个人支付账户返现记录,个人提现手续费配置;
//
//审核事件管理,审核类型审核流程配置;
//
//商户模板路由,模板路由管理,银联二级商户管理;
//
//服务商管理;
//
//银联二级商户代码,微信支付宝子商户号管理,默认路由,通道费率管理,通道商户号管理;
//
//认证/短信通道管理,认证/短信路由管理;
//
//交易订单查询,退款订单查询,出款订单查询,转账订单查询,资金代发绑卡认证查询,模板路由订单查询,电子章使用记录查询,认证订单查询;
//
//入金订单手续费查询,商户对账单查询,出款订单手续费查询,购付汇订单手续费查询,收结汇订单手续费查询;
//
//分账流水查询;
//
//商户账户查询,商户账户明细查询,控制余额查询,商户账户产品限额;
//
//内部账户查询,内部账户明细查询;
//
//个人账户查询,个人账户明细查询,个人账户限额设置;
//
//商户日交易统计查询,商户周期交易统计查询,商户账户日终余额表,操作日志查询,生产运维信息发送报文,自由格式报文,交易量分析报表;
//
//购汇订单管理,付汇管理,境外收款账户管理;
//
//商户收汇通知管理,商户收汇申请管理,商户结汇申请管理;
//
//通关订单管理;
//
//数据字典类型,数据字典,银行编码管理,公告管理;
//
//网联商户信息报送,银联商户信息报送;

    }

    /**
     * 获取左补位自增流水
     *
     * @param key
     * @param size
     * @param par
     * @return
     */
    private String getIncreasingNos(String key, int size, char par) {
        String increasingNo = "";
//        try{
//            increasingNo = StringUtils.leftPad(
//                    String.valueOf(new RedisAtomicLong(key, redisTemplate.getConnectionFactory()).getAndIncrement()),
//                    size,par);
//        }catch (Exception e){
//            throw new CommonException(CleErrorEnum.E7015);
//        }
        return increasingNo;
    }

    public String getOrderOutNo() {
        StringBuilder str = new StringBuilder();
//        //清算
//        str.append(CommonConstants.QS);
//        //出款
//        str.append(CommonConstants.TRADE_TYPE_3);
//        //今日日期
//        str.append(DateUtil.format(new Date(),"yyyyMMddHHmmss"));
//        String serialNo = getIncreasingNo(CommonConstants.QS+CommonConstants.TRADE_TYPE_3,6,'0');
//        str.append(serialNo);
//        System.out.println("生成内部出款订单号"+str);
        return str.toString();
    }

    public void s2() {
//自动结算订单查询,支付订单查询,退款订单查询,转账到银行卡查询,提现查询,转账订单查询,充值订单查询,资金代发订单查询,电子章使用记录查询;
//
//银行卡管理,转账到银行卡申请,转账到银行卡复核;
//
//商户盗料,修改登陆密码,修改支付密码;
//
//操作员管理,权限管理,操作日志;
//
//绑定个人管理,绑定商户管理,订单分账流水,失败待处理订单;
//
//账户明细查询,对账单查询,账户日终余额表;
//
//代发银行卡,资金代发发起,资金代发复核;
//
//支付账户转账,绑定商户管理,绑定个人管理;
    }

    public void s1() {
//商户基本信息,商户结算信息,商户费率管理,商户指定路由配置,商户即时结算,商户密钥查询,商户正件到到期预警,自主入网商户审核,资金代发商户配置,商户访问IP白名单,商户绑定关系,商户充值费率管理,商户电子协议管理,移动二维码,跨境商户绑定关系,商户批量导入;
//
//代理商基本信息;
//
//销售基本信息,分公司基本信息,部门基本信息,平台号管理;
//
//个人基本信息,个人绑卡信息,个人实名认证记录,个人支付账户返现设置,个人支付账户返现记录,个人提现手续费配置;
//
//审核事件管理,审核类型审核流程配置;
//
//商户模板路由,模板路由管理,银联二级商户管理;
//
//服务商管理;
//
//银联二级商户代码,微信支付宝子商户号管理,默认路由,通道费率管理,通道商户号管理;
//
//认证/短信通道管理,认证/短信路由管理;
//
//交易订单查询,退款订单查询,出款订单查询,转账订单查询,资金代发绑卡认证查询,模板路由订单查询,电子章使用记录查询,认证订单查询;
//
//入金订单手续费查询,商户对账单查询,出款订单手续费查询,购付汇订单手续费查询,收结汇订单手续费查询;
//
//分账流水查询;
//
//商户账户查询,商户账户明细查询,控制余额查询,商户账户产品限额;
//
//内部账户查询,内部账户明细查询;
//
//个人账户查询,个人账户明细查询,个人账户限额设置;
//
//商户日交易统计查询,商户周期交易统计查询,商户账户日终余额表,操作日志查询,生产运维信息发送报文,自由格式报文,交易量分析报表;
//
//购汇订单管理,付汇管理,境外收款账户管理;
//
//商户收汇通知管理,商户收汇申请管理,商户结汇申请管理;
//
//通关订单管理;
//
//数据字典类型,数据字典,银行编码管理,公告管理;
//
//网联商户信息报送,银联商户信息报送;

    }

    /**
     * 获取左补位自增流水
     *
     * @param key
     * @param size
     * @param par
     * @return
     */
    private String getIncreasingNo(String key, int size, char par) {
        String increasingNo = "";
//        try{
//            increasingNo = StringUtils.leftPad(
//                    String.valueOf(new RedisAtomicLong(key, redisTemplate.getConnectionFactory()).getAndIncrement()),
//                    size,par);
//        }catch (Exception e){
//            throw new CommonException(CleErrorEnum.E7015);
//        }
        return increasingNo;
    }

    /**
     * 获取文件后缀的方法
     *
     * @param file 要获取文件后缀的文件
     * @return 文件后缀
     * @author https://www.4spaces.org/
     */
    public String getFileExtension(File file) {
        String extension = "";
        try {
            if (file != null && file.exists()) {
                String name = file.getName();
                extension = name.substring(name.lastIndexOf("."));
            }
        } catch (Exception e) {
            extension = "";
        }
        return extension;
    }
}
